<?php if(isset($notification)):?>
<b><?=$notification?></b>
<?php else:?>

<script type="text/javascript">

    window.addEvent('domready', function() {

        $('addwidget').addEvent('submit', function(e) {
            
            e.stop();
            $('ajax-loader').removeClass('hide');
            
            this.set('send', {
                url : '<?=current_url()?>',
                onComplete: function(response) {

                    if (response.test('<b><?=lang('widget_add_success')?></b>')) {

                        ModalBoxClose();
                        ajax_url('<?=modul_url('widgets', true)?>', 'main_content');
                    }
                    else {

                        $('form_error').set('html', response);
                    }
                }
            });
            
            this.send();
        });

        $('widget_modul').addEvent('change', function(e) {

            e.stop();
            ajax_post('<?=modul_url("widgets/load", true);?>', 'drop_method', {modul:this.value});
        });

      //Tabs
        new SimpleTabs($('tab'), {
            selector: 'h4',
            onSelect: function(toggle, container, index) {

                toggle.addClass('tab-selected');
                container.setStyle('display', '');

                if (index == 1) {
                    
                    var mod = $('widget_modul').get('value');
                    var meth = $('widget_method').get('value');

                    ajax_post('<?=modul_url("widgets/params", true);?>', container, {modul: mod, method: meth});
                }
            }
        });

        var options_slide = function() {

            if ($('cache_options_slide').checked) {

                $('cache_options').setStyle('display', 'block');
            }
            else {

                $('cache_options').setStyle('display', 'none');
            }
        }

        options_slide();
        $('cache_options_slide').addEvent('click', options_slide);
    });
</script>

<?=form_open(current_url(), array('class' => 'hform', 'id' => 'addwidget'), array('add' => true));?>

<span id="form_error"></span>

<div id="tab">
    <h4>Основные</h4>
    <div>
        <p>
            <label><?=lang('widget_field_container')?></label>
            <?=form_dropdown('container', $containers, set_value('container'))?>
        </p>
        <p>
            <label><?=lang('widget_field_title')?></label>
            <?=form_input('title', set_value('title'))?>
        </p>
        <p>
            <label><?=lang('widget_field_modul')?></label>
            <?=form_dropdown('modul', $modules, set_value('modul'), 'id="widget_modul"')?>
        </p>
        <p>
            <label><?=lang('widget_field_method')?></label>
            <span id="drop_method"><?=form_dropdown('method', $methods, set_value('method'), 'id="widget_method"')?></span>
        </p>
        <p>
            <label><?=lang('widget_field_order')?></label>
            <?=form_input('order', set_value('order'))?>
        </p>
    </div>
    
    <h4>Параметры</h4>
    <div>
        
    </div>
    
    <h4>Кэширование</h4>
    <div>
        <p>
            <label><?=lang('widget_cache_enable')?></label>
            <?=form_checkbox('cache_enable', 1, false, 'id="cache_options_slide"')?>
        </p>
        
        <span id="cache_options" style="display: none;">
        <b><?=lang('widget_cache_option')?></b>
        <p>
            <label><?=lang('widget_cache_usergroup')?></label>
            <?=form_checkbox('cache[usergroup]', 1)?>
        </p>
        <p>
            <label><?=lang('widget_cache_userid')?></label>
            <?=form_checkbox('cache[userid]', 1)?>
        </p>
        <p>
            <label><?=lang('widget_cache_segment')?></label>
            <?=form_input('cache[segment]', 0)?>
        </p>
        <p>
            <label><?=lang('widget_cache_reload')?></label>
            <?=form_input('cache[reload]', 0)?>
        </p>
        </span>
    </div>
</div>
<?=form_submit('add', lang('add'));?> <?=form_reset('reset', lang('reset'));?>

</form>
<?php endif;?>